<?php
namespace Admin\Controller;
use Think\Page;

/**
 * 学生管理控制器
 * @author水月居 <singliang@163.com>
 */
class XbkcController extends AdminController {

    /**
     * 用户管理首页
    */
    public function index(){
		$sclass = I('class')?I('class'):"请选择班级" ; //设置学生班级
		$where=I('class')?array("class"=>I('class'),"status"=>"1"):array("status"=>"1");
		
        $student=D("student");
		$list=$student->relation(true)->order("sid asc")->where($where)->limit(45)->select();
		//dump($list);
		$class=M('class')->field("class")->select();//获取全校班级列表
	    $this->assign('_sclass',$sclass);
		$this->assign('_class', $class);
        $this->assign('_list', $list);
        $this->meta_title = '学生信息';
        $this->display();
    }

    /**
     * 修改学生课程信息初始化
     * @author huajie <banhuajie@163.com>
     */
    
	public function select_curriculum(){
		$student = M('student')->find(I('sid'));
        $this->assign('student', $student);
		$map['grade'] =array('like',"%".$student['grade']."%");
        $curriculum=M('curriculum')->where($map)->select();
		
		//$curriculum=$sql->getLastSql();
		//dump($curriculum);
		$this->assign('curriculum', $curriculum);
		$this->assign('student', $student);
		$this->meta_title = '学生选课';
        $this->display();
    }

//保存学生选课信息

   	public function saveStudentCurriculum(){

        $data = array(
            'sid'             => I('sid'),
            'cid'             => I('cid'),
            'update_time' => NOW_TIME,
            'update_ip'   => get_client_ip(1),
        );

            //dump($data);

		$res = D('student')->save($data);



        if(!$res){
            $this->error(D('student')->getError());
        }else{
            $this->success('选课成功！', U('xbkc/index'));
        }
    }
	public function updateStudent(){
        $nickname = M('student')->getFieldBySid(sid, 'name');
        $this->assign('name', $name);
        $this->meta_title = '学生选课';
        $this->display();
    }

    



   
}